// 
// Bachelor of Software Engineering
// Media Design School
// Auckland
// New Zealand
//
// (c) 2005 - 2014 Media Design School
//
// File Name	: WinStack.cpp
// Desrciption	: CWinStack implementation file.
// Author(s)	: Hayden Asplet.
// Mail			: hayden.asplet@mediadesignschool.com
//

// PCH
#include "SolitaireStd.h"

// Library Includes

// This Include
#include "WinStack.h"

// Local Includes


CWinStack::CWinStack()
	:CCardStack()
{
}

CWinStack::CWinStack(const CPoint& _krPosition, int _iOffset, const EStackDirection& _krDirection)
	:CCardStack(_krPosition, _iOffset, _krDirection)
{

}


CWinStack::CWinStack(const CWinStack& _krStack)
	:CCardStack(_krStack)
{

}

CWinStack::~CWinStack()
{
}

bool CWinStack::CanBePushed(const CPlayingCard& _krCard)
{
	if(IsEmpty() && m_lerpingCards.empty()) {
		if(_krCard.GetValue() == keAce) {
			return true;
		}
		else {
			return false;
		}
	}

	CPlayingCard topCard;

	if(!m_lerpingCards.empty()) {
		topCard = m_lerpingCards.back();
	}
	else {
		topCard = Peek();
	}

	if(topCard.IsFaceDown()) {
		return false;
	}
	else if(_krCard.GetValue() == topCard.GetValue() + 1) {
		if(_krCard.GetSuit() == topCard.GetSuit()) {
		// Same suit.
			return true;
		}
		else {
		// Different suits.
			return false;
		}
	}

	return false;
}

bool CWinStack::CanBePushed(const TStack& _krStack)
{
	if(_krStack.empty() || _krStack.size() > 1) {
		return false;
	}

	CPlayingCard bottomCard = _krStack[0];

	if(IsEmpty() && m_lerpingCards.empty()) {
		if(bottomCard.GetValue() == keAce) {
			return true;
		}
		else {
			return false;
		}
	}

	CPlayingCard topCard;

	if(!m_lerpingCards.empty()) {
		topCard = m_lerpingCards.back();
	}
	else {
		topCard = Peek();
	}

	if(topCard.IsFaceDown()) {
		return false;
	}
	else if(bottomCard.GetValue() == topCard.GetValue() + 1) {
		if(topCard.GetSuit() == bottomCard.GetSuit()) {
		// Same suit.
			return true;
		}
		else {
		// Different suits.
			return false;
		}
	}

	return false;
}